<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="./css/style.min.css">
    <title>修改密码</title>
</head>
<script type="text/javascript">
    window.onload=function () {
            document.addEventListener('touchstart',function (event) {
                if(event.touches.length>1){
                    event.preventDefault();
                }
            })
            var lastTouchEnd=0;
            document.addEventListener('touchend',function (event) {
                var now=(new Date()).getTime();
                if(now-lastTouchEnd<=300){
                    event.preventDefault();
                }
                lastTouchEnd=now;
            },false)
        }
</script>

<body>
    <div id="personal_center">
        <div class="t-container t-mp-container">
            <header class="cl" v-show="header.show">
                <div class="nav-bar cl">
                    <span class="goback arrow_l" @click="goback"></span>
                    <span class="page-name" v-cloak>{{shop_name}}会员店</span>
                </div>
            </header>
            <div class="t-main">
                <form action="">
                    <div class="modify-password-content">
                        <div class="t-input-group">
                            <input type="text" placeholder="请输入原密码" v-model="password">
                        </div>
                        <div class="t-input-group">
                            <input type="text" placeholder="请输入新密码" v-model="newpassword">
                        </div>
                        <div class="t-input-group">
                            <input type="text" placeholder="请确认新密码" v-model="repassword">
                        </div>
                        <div class="t-mp-footer">
                            <button type="button" @click="save">确认</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <toast ref="toast"></toast>
    </div>
    <script src="./js/lib/vue.js"></script>
    <script src="http://static.jdhui.com/lib/vue-resource/1.2/vue-resource.js"></script>
    <script src="./js/min/config.min.js"></script>
    <script src="./js/min/common.min.js"></script>
    <script src="./js/min/component.min.js"></script>
    <script>
        var toast = new component.popup.toast();
        var app = new Vue({
            el: '#personal_center',
            data: {
                header: {
                    show: !APP.iswechat()
                },
                password: '',
                newpassword: '',
                repassword: '',
                store_id: APP.getQueryString('storeid'),
                shop_name: ''
            },
            components: {
                'toast': toast
            },
            mounted: function() {
                APP.init(this, function() {
                    this.shop_name = APP.getCookie('shopname');
                }.bind(this), function(arg) {
                    this.shop_name = arg.body.data.shop.shop_name;
                }.bind(this));
            },
            methods: {
                goback: function() {
                    window.history.go(-1);
                },
                save: function() {
                    if (this.password == '') {
                        this.$refs.toast.show('请填写原密码');
                        return;
                    }
                    if (this.newpassword == '') {
                        this.$refs.toast.show('请填写新密码');
                        return;
                    }
                    if (this.repassword == '') {
                        this.$refs.toast.show('请填写确认密码');
                        return;
                    }
                    if (!/^[a-zA-Z0-9]{6,18}$/.test(this.newpassword)) {
                        this.$refs.toast.show('请填写6-18位数字或者英文新密码');
                        return;
                    }
                    if (this.newpassword != this.repassword) {
                        this.$refs.toast.show('新密码和确认密码不一致');
                        return;
                    }
                    Vue.http.post(APIPHP + 'index.php?r=member/u/edit-pwd', {
                        password: this.password,
                        newpassword: this.newpassword,
                        repassword: this.repassword,
                        act: 1,
                        storeid: this.store_id
                    }, {
                        emulateJSON: true
                    }).then(function(_res) {
                        if (_res.body.flag == 1) {
                            window.location.href = 'login.html?storeid=' + this.store_id;
                        } else {
                            this.$refs.toast.show(_res.body.msg);
                        }
                    }.bind(this), function(err) {
                        console.log("err")
                    })
                }
            }
        })
    </script>
</body>

</html>